// const { aes } = require
const { md5 } = require('../../utils/crypto-util');
/**
 * 用户模型 
 * 
*/
module.exports = (sequelize, Sequelize) => {
    return sequelize.define("users", {
        id: {
            type: Sequelize.UUID, // 数据类型
            notNull: true, // 值不能为null
            primaryKey: true, // 主键
            comment: '唯一标识',
            defaultValue: Sequelize.UUIDV4, // 或 DataTypes.UUIDV1
            // get() { // UUID的自动递增
            //     return () => {
            //         return this.getDataValue('id');
            //     };
            // }
        },
        userId: {
            type: Sequelize.STRING,
            notNull: true,
            notEmpty: true, // 不能为空
            comment: '账号',
            defaultValue: 'admin',
            field:'user_id'
        },
        nickname: {
            type: Sequelize.STRING,
            notNull: true,
            notEmpty: true, // 不能为空字符串
            comment: '昵称',
            defaultValue: '',
            field:'nickname'
        },
        avatar: {
            type: Sequelize.STRING,
            comment: '头像',
        },
        slogan: {
            type: Sequelize.STRING,
            comment: '格言',
        },
        sex: {
            type: Sequelize.INTEGER,
            comment: '性别'
        },
        // roleId: {
        //     // type: Sequelize.STRING(2), // varchar类型 长度为2
        //     type: Sequelize.STRING,
        //     notEmpty: true, // 不能为空
        //     comment: '角色名称',
        //     field:'role_id'
        // },
        password: {
            type: Sequelize.STRING,
            notEmpty: true,
            comment: '密码',
            defaultValue: '',
            set(value) {
                // 在数据库中以明文形式存储密码是很糟糕的
                // 使用MD5二次加密
                this.setDataValue('password', md5(value));
            }
        },
        phoneNumber: {
            type: Sequelize.STRING(11),
            comment: '电话号码',
            field:'phone_number'
        },
        eMail: {
            type: Sequelize.STRING,
            comment: '邮箱'
        },
        state: {
            type: Sequelize.INTEGER,
            comment: '状态 0:封禁 1:正常',
            defaultValue: true
        },
        commentsCount: {
            type: Sequelize.INTEGER,
            notEmpty: true,
            defaultValue: 0,
            comment: '用户评论数',
            field:'comments_count'
        },
        likesCount: {
            type: Sequelize.INTEGER,
            notEmpty: true,
            defaultValue: 0,
            comment: '用户点赞数',
            field:'likes_count'
        },
        danmuCount: {
            type: Sequelize.INTEGER,
            notEmpty: true,
            defaultValue: 0,
            comment: '用户弹幕数',
            field:'danmu_count'
        }
    })
}